package ua.pp.parkee;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.attribute.FileTime;

/**
 * Hello world!
 *
 */
public class ClassLoaderTester
{
    public static final String MODULE = "ua.pp.parkee.TestModule";

    public static void main( String[] args ) throws ClassNotFoundException, IllegalAccessException, InstantiationException, InterruptedException, IOException {

        MyClassLoader myClassLoader;
        Class testModuleClass;

        Object object = null;

        Path src = MyClassLoader.getSourcePath(MODULE);
        Path target = MyClassLoader.getTargetPath(MODULE);

        FileTime srcLastModifiedTime;
        FileTime targetLastModifiedTime;

        while (true) {


            myClassLoader = new MyClassLoader();
            testModuleClass = myClassLoader.loadClass(MODULE);
            if (testModuleClass != null) {
                object = testModuleClass.newInstance();
            }

            System.out.println(object);


            srcLastModifiedTime = Files.getLastModifiedTime(src);
            targetLastModifiedTime = Files.getLastModifiedTime(target);
            while (srcLastModifiedTime.compareTo(targetLastModifiedTime) <= 0) {
                srcLastModifiedTime = Files.getLastModifiedTime(src);
                targetLastModifiedTime = Files.getLastModifiedTime(target);
                Thread.sleep(1000);
            }
        }


    }
}
